package com.server.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.server.authority.Login;
import com.server.common.base.ProjectInfo;
import com.server.common.base.SessionData;
import com.server.navigater.INavigaterService;
import com.server.service.INoticeService;
import com.server.web.SessionUtil;

@Controller
@RequestMapping("")
public class IndexController {
	
	@Autowired
	private INavigaterService navigaterService;
	@Autowired
	private ProjectInfo projectInfo;
	@Autowired
	private INoticeService noticeService;


	@RequestMapping("")
	public ModelAndView index(HttpServletRequest request) {
		ModelAndView mv = new ModelAndView("home/home");
		mv.addObject("projectName", projectInfo.getProjectName());
		mv.addObject("rootPath", projectInfo.getProjectRootPath());
		Map<String, Object> map = noticeService.getNotice();
		mv.addAllObjects(map);
		return mv;
	}
	
	@Login
	@RequestMapping("mng")
	public ModelAndView manager(HttpServletRequest request) {
		ModelAndView mv = new ModelAndView("index");
		mv.addObject("loginName", SessionUtil.getStringAttri(request, SessionData.loginNameKey));
		mv.addObject("userName", SessionUtil.getStringAttri(request, SessionData.nameKey));
		
		Integer levelKey = 1;
		Integer typeObj = SessionUtil.getIntAttri(request, SessionData.levelKey);
		if (typeObj.equals(9)) {//超级管理员
			levelKey = 3;
		}else if (typeObj.equals(8)||typeObj.equals(7)) {//公司管理员和财务总管
			levelKey = 2;
		}
		
		mv.addObject("leftNavi", navigaterService.getNaviTree(1, levelKey));
		mv.addObject("projectName", projectInfo.getProjectName());
		mv.addObject("rootPath", projectInfo.getProjectRootPath());
		return mv;
	}

}